package work;

import complexity.Queue;

import java.util.HashSet;
import java.util.TreeSet;

public class PageFolder {
    public static void main(String[] args) {
        Node<String> node = setTree(1);
        printTree(node);
    }
    public static Node<String> setTree(int N){
        Node<String> root =null;
        Queue<Node<String>> queue = new Queue<>();
        for (int i = 0; i < N; i++) {
            if (i==0){
                root = new Node<String>(null,null,"down");
            }
            queue.enqueue(root);
            while (!queue.isEmpty()){
                Node<String> node = queue.dequeue();
                if (node.left!=null){
                    queue.enqueue(node.left);
                }
                if (node.right!=null){
                    queue.enqueue(node.right);
                }
                if (node.left==null&&node.right==null){
                   node.left =  new Node<String>(null,null,"down");
                   node.right = new Node<String>(null,null,"up");
                }
            }
        }
        return root;
    }
    public static void printTree( Node<String> node){
        Queue<Node> nodes = new Queue<>();
        printLine(nodes,node);
        for (Node no : nodes) {
            System.out.println(no.data);
        }
    }
    public static void printLine(Queue<Node> queue, Node<String> node){
        if (node==null){
            return;
        }
        if (node.left!=null){
            printLine(queue,node.left);
        }
        queue.enqueue(node);
        if (node.right!=null){
            printLine(queue,node.right);
        }
    }
    private static class Node<T> {
        private Node<String> left;
        private Node<String> right;
        private T data;

        public Node(Node<String> left, Node<String> right, T data) {
            this.left = left;
            this.right = right;
            this.data = data;
        }
    }
}
